// The headers that we need
//#include "stdafx.h"
#include "Terrain.h"
#include "Interface.h"
#include "Keyboard.h"
#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>

using namespace std;


/* This is an initialization function.
In this function you usually set things that need to be executed one like the shadeing model. Not that it would be the purpose of this tutorial but the // shadeing model is what gives you the impression of volume: some part of your object are more lit then others. This color difference is what makes you think it's 3D.*/
Interface inter;
Terrain terrain;
void init(void) 
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glShadeModel (GL_FLAT);
	inter.set_values("hello");
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);//clear screen
	terrain.Draw();
	glFlush();
	glutSwapBuffers();
	
}
/* This function is called when the window is resized. w and h will be the new width and height of the screen. Some adjusting needs to be made if the screen is resized but I woun't get into any details for now.*/
void reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei) w, (GLsizei) h); 
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
	glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv)
{
	//Terrain terr;
	//terr.set_values(3,4);
	//cout << "area: " << terr.area();

	// initialize GLUT
	glutInit(&argc, argv);
	/*This is where you tell glut if you want a single buffer or a double buffered window.
	GLUT_RGB tells what kind of color system you want. We could have chosen GLUT_RGBA too if we needed the alpha component of the color.*/
	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
	// These are the coordinates and size of the window that will be opened.
	glutInitWindowSize (700, 700); 
	glutInitWindowPosition (100, 100);
	// Create the window now!
	glutCreateWindow (argv[0]);
	init ();
	/*Glut is an event based framework. You don't actually control anything. You tell GLUT where and when to call your functions to do your stuff. It's like "Don't call us...we'll call you :D". All you have to do is have the right signature for a function (the right parameters) and give GLUT the pointer to it. It will call it at the right time with the right arguments
	This is how you register a display function. Actualy this is how you register all functions...by passing a pointer to opengl saying: this is the function you need to call to render my scene. This goes for all other events like mouse, keyboard and reshape.*/
	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(Keyboard::press);
	// This call will give the control to glut. It will loop infinitly and call your functions when the events you registered with happen.
	glutMainLoop();
	return 0;
}